package org.example.lotterysystem.controller;

import jakarta.annotation.Resource;
import org.example.lotterysystem.common.domain.Result;
import org.example.lotterysystem.common.domain.dto.DrawPrizeDTO;
import org.example.lotterysystem.common.domain.dto.ShowWinningRecordsDTO;
import org.example.lotterysystem.common.domain.vo.WinningRecordVO;
import org.example.lotterysystem.service.DrawPrizeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DrawPrizeController {
    @Resource
    DrawPrizeService drawPrizeService;

    /**
     * 抽奖
     */
    @RequestMapping("/draw-prize")
    public Result<Boolean> drawPrize(
            @Validated @RequestBody DrawPrizeDTO drawPrizeDTO){
        //异步抽奖
        drawPrizeService.drawPrize(drawPrizeDTO);

        return Result.success(true);
    }

    /**
     *获取抽奖结果
     */
    @RequestMapping("/winning-records/show")
    public Result<List<WinningRecordVO>> showWinningRecords(
            @Validated @RequestBody ShowWinningRecordsDTO param){
        return Result.success(drawPrizeService.getRecords(param));
    }
}
